package com.dyson.jedis;

import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @Author: Wy
 * @Email: DysonWy@foxMail.com
 * @Time: 2020/3/2 18:30
 * @Description:
 */
public class JedisPoolInstance {

    public static String host = "192.168.181.128";
    public static int port = 6379;
    public static String pwd = "root";
    public static int timeOut = 20 * 1000;
    public static JedisPool jedisPool = null;

    private JedisPoolInstance() {

    }

    public static JedisPool getJedisPool() {
        if (jedisPool == null) {
            synchronized (JedisPoolInstance.class) {
                if (jedisPool == null) {
                    JedisPoolConfig poolConfig = new JedisPoolConfig();
                    poolConfig.setMaxTotal(100);//最大连接数
                    poolConfig.setMaxIdle(10);//最大空闲链接
                    poolConfig.setMaxWaitMillis(10 * 1000);//获取链接最大等待毫秒数
                    poolConfig.setTestOnBorrow(true);//获取链接检查链接有效性
                    jedisPool = new JedisPool(poolConfig, host, port, timeOut, pwd);
                }
            }
        }
        return jedisPool;
    }
}
